package com.wanmait.wisdom.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.wisdom.entity.ResidentType;

import com.wanmait.wisdom.manage.service.ManageResidentTypeService;
import com.wanmait.wisdom.mapper.ResidentTypeMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class ManageResidentTypeServiceImpl extends ServiceImpl<ResidentTypeMapper,ResidentType> implements ManageResidentTypeService{
    @Resource
    private ResidentTypeMapper residentTypeMapper;
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    @Cacheable("residentTypeList")
    public List<ResidentType> findAllResidentType() {
        LambdaQueryWrapper<ResidentType> queryWrapper = new LambdaQueryWrapper<>();
        redisTemplate.opsForValue().set("residentTypeList",residentTypeMapper.selectList(queryWrapper.orderByAsc(ResidentType::getSort)),1, TimeUnit.HOURS);
        return residentTypeMapper.selectList(queryWrapper.orderByAsc(ResidentType::getSort));
    }
}
